home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group98c.txt
/
000142_icon-group-sender _Thu Dec 17 16:31:35 1998.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id QAA26236
for icon-group-addresses; Thu, 17 Dec 1998 16:31:29 -0700 (MST)
Message-Id: <199812172331.QAA26236@baskerville.CS.Arizona.EDU>
Date: Thu, 17 Dec 1998 13:36:27 -0700
From: Steve Wampler <swampler@gemini.edu>
X-Accept-Language: en
To: icon-group@optima.CS.Arizona.EDU
Subject: Re: Small Icon programming problem
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
Ralph Griswold wrote:
>
> Here's a small Icon programming problem for you to tackle:
>
> Write a procedure digsort(i) that returns the integer that
> results from sorting the digits of i, preserving sign. For
> example, digsort(201) should return 12 and digsort(-1042)
> should return -124. You may assume i is an integer.
>
> You could aim for brevity, speed, and/or clarity.
>
> Send solutions and comments to icon-group. The most interesting
> solutions will appear in a future issue of the Icon Analyst and
> sent to icon-group as a package.
Well, here's one that is short and obscure. I have another, similar
one that avoids the int->string and string->int conversions, but it
runs ~20% slower than this one.
procedure digsort(i)
local a,s
every put(a := [], !i) # separate the digits and sign
every (s := "", s ||:= !sort(a)) # sort and rejoin (string conversion)
return integer(s) # convert back to integer
end
--
Steve Wampler (swampler@gemini.edu)